package com.zhoushihao.class0820;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

public class BestScore {
    public static void main(String[] args) {
        Map<String, Double> scores = new HashMap<>();
        try (
                BufferedReader br = new BufferedReader(new FileReader("C:/Users/周士好/Desktop/homework/模拟题/2.txt"));
                BufferedWriter bw = new BufferedWriter(new FileWriter("C:/Users/周士好/Desktop/homework/模拟题/3.txt"))
                ) {
            String line;
            while ((line = br.readLine()) != null) {
                String[] arr = line.split(",");
                String name = arr[0];
                String[] split = arr[1].split(":");
                double score = Double.parseDouble(split[0]) * 60 + Double.parseDouble(split[1]);
                if (!scores.containsKey(name)) {
                    scores.put(name, score);
                }else{
                    scores.put(name, Math.min(scores.get(name),score));
                }
            }
            for (Map.Entry<String, Double> entry : scores.entrySet()) {
                double score = entry.getValue();
                int minutes = (int)score/60;
                String seconds = String.format("%.3f", score - minutes*60);
                bw.write(entry.getKey() + "," + minutes + ":" + seconds);
                bw.newLine();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
